{extend name="public:base" /}
{block name="style"}
<link rel="stylesheet" type="text/css" href="__INDEX__/css/public.css">
<link rel="stylesheet" type="text/css" href="__INDEX__/css/style.css">
<link rel="stylesheet" type="text/css" href="__INDEX__/css/responsive.css">
<link rel="shortcut icon" href="__INDEX__/images/favorite.ico">
<link rel="stylesheet" type="text/css" href="__COMMON__/css/style.css">
{/block}
{block name="html"}
{include file="index@public/main" /}
<div class="right_style">
    <h3 class="title_style"><em></em><span>添加银行卡</span></h3>
	<div class="tixian">
		<!-- <h1 class="h1">银行卡绑定</h1> -->
        <select name="bank" id="bank">
            <option value="工商银行" >工商银行</option>
            <option value="农业银行" >农业银行</option>
            <option value="农商银行" >农商银行</option>
            <option value="建设银行" >建设银行</option>
            <option value="中国银行" >中国银行</option>
            <option value="招商银行" >招商银行</option>
            <option value="平安银行" >平安银行</option>
            <option value="兴业银行" >兴业银行</option>
            <option value="中国邮政" >中国邮政</option>
        </select>
        <input type="text" name="name" placeholder="输入持卡人姓名" />
        <input type="number" name="card_num" placeholder="输入银行卡号" />
        <input type="text" name="branch" placeholder="输入开户支行" />
		<div>
			<ul class="ulist">
				<li class="group">
					<label class="label" for="phone"></label>
					<div class="controls">
						<input type="number" name="mobile" placeholder="手机号码" id="phone" class="txt">
					</div>
				</li>
				<li class="group">
					<div class="controls">
						<input type="number" name="verify_code" placeholder="验证码" id="code" class="txt">
						<!--<a class="btn btn-small get-code" id="get-code" style="text-align:center;width: 30%;height:40px;display: block;position: absolute;margin-top:-40px;right:10%;line-height: 40px;" value="获取验证码" onclick="getCode(this)" />获取验证码</a>-->
						<button class="btn btn-small get-code" id="get-code" style="text-align:center;width: 30%;height:40px;display: block;position: absolute;margin-top:-40px;right:10%;color:#fff;line-height: 40px;background:#de484f;border:0px;" value="获取验证码" onclick="getCode(this)" />获取验证码</button>

					</div>
				</li>
			</ul>
		</div>
		<input type="button" value="提交" id="submitCard"/>
		<p>温馨提示：绑定的银行卡绑定后不可以更改，请确定后再进行绑定。</p>
	</div>
</div>
{/block}

{block name="javascript"}
<script src="__INDEX__/js/jquery-1.9.1.min.js"></script>
<script src="__INDEX__/js/public.js"></script>
<script src="__INDEX__/layer/layer.js"></script>
<script src="__COMMON__/js/area.js"></script>
<script src="__COMMON__/js/select.js"></script>
<script>

    $("#submitCard").click(function(){

        var c = $("input[name='card_num']").val();
        var b = $("#bank").val();
        var n = $("input[name='name']").val();
        var m = $("input[name='mobile']").val();
        var d = $("input[name='verify_code']").val();
        var branch = $("input[name='branch']").val();

        if( c == "" ){
            alert("请输入正确银行卡号");
            return false;
        }

        if(branch.match(/^[\u4e00-\u9fa5]+(·[\u4e00-\u9fa5]+)*$/) == null){
            alert("请输入正确银行及开户支行");
            return false;
        }

        if(n.match(/^[\u4e00-\u9fa5]+(·[\u4e00-\u9fa5]+)*$/) == null){
            alert("请输入正确持卡人姓名");
            return false;
        }

        if(m.match(/^1[34578]\d{9}$/) == null){
            alert("请填写正确手机号码格式");
            return false;
        }

        if(d.match(/^\d{6}$/) == null){
            alert("请输入验证码");
            return false;
        }

        $.ajax({
            type: 'POST',
            url: '{:url("Deposit/card")}',
            dataType: 'json',
            data: {
                c: c,
                b: b,
                n: n,
                m: m,
				d: d,
                branch:branch
            },
            success: function (data) {

                if( data.result == 0 ){

                    window.location.href='{:url("User/index")}';

                }else if(data == 1){

                    alert("验证码有误");

                }else if(data == 2){

					alert("只能绑定自己的卡");

				}else if(data == 3){

					alert("卡号已存在");

				}else{

                    alert(data.msg);
				}
            }
        });
    });

    function getCode() {
        var timer=null,num=60;
        var mobile = $('#phone').val();
        if ("" == mobile || !mobile) {
            alert("请输入手机号!");
            return false;
        } else {
            var reg = /^0?1[3|4|5|7|8][0-9]\d{8}$/;
            //验证规则
            if (!reg.test(mobile)) {
                alert("手机号格式错误!");
                return false;
            }
        }
        $.ajax({
            type: 'POST',
            url: '{:url("Deposit/card_code")}',
            dataType: 'json',
            data: {mobile: mobile},
            success: function (data) {

                if( data.result == 0 ){
                    alert(data.msg);
                    timer=setInterval(function(){
                        $(".get-code").attr("disabled","disabled")
                        $(".get-code").text(num+"s"+"重新发送");
                        if(num<0){
                            $(".get-code").text("获取验证码 ");
                            $(".get-code").removeAttr("disabled")
                            clearInterval(timer);
                        }
                        num--;
                    },1000);
                }else{
                    alert(data.msg);
                }
            }
        });
    }


</script>


{/block}
